package com.yc.test.proxy;

import lombok.Data;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;


@Data
public class ZooInvacationHandler implements InvocationHandler {

    private IAnimal animal;

    public void cry() {
        IAnimal animal = (IAnimal) Proxy.newProxyInstance(IAnimal.class.getClassLoader(), new Class[]{IAnimal.class}, this);
        animal.cry();
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("增强：开始叫");
        Object result = method.invoke(animal, args);
        System.out.println("增强：结束叫");
        return result;
    }
}
